{% extends 'admin/common/base.html' %}
{% block body %}

<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="role-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                栏目标题：<input type="text" name="title" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success {{check_perms('cms:category:add')}}" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled {{check_perms('cms:category:edit')}}" onclick="$.operate.edit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-tree-table"></table>
            </div>
        </div>
    </div>
</body>
{% endblock %}
{% block js %}
{{ super() }}
<script>
    var addFlag = "{{check_perms('cms:category:add')}}";
    var editFlag = "{{check_perms('cms:category:edit')}}";
    var removeFlag = "{{check_perms('cms:category:remove')}}";
    var tpl_mold_datas = {{get_dict_data('cms_category_tpl_mold') | tojson | safe}};
    var visible_datas = {{get_dict_data('cms_visible') | tojson | safe}};
    $(function () {
        var options = {
            code: "id",
            parentCode: "parent_id",
            uniqueId: "id",
            expandAll: false,
            expandFirst: false,
            url: "{{url_for('admin.cms.category.list')}}",
            createUrl: "{{url_for('admin.cms.category.add')}}?parent_id={id}",
            updateUrl: "{{url_for('admin.cms.category.edit')}}?id={id}",
            removeUrl: "{{url_for('admin.cms.category.remove')}}?ids={id}",
            exportUrl: "{{url_for('admin.cms.category.export')}}",
            modalName: "栏目",
            columns: [
            {
                field: 'selectItem', 
                radio: true
            },
            {
                field: 'title',
                title: '栏目标题',
                width: '20',
                widthUnit: '%',
                formatter: function(value, row, index) {
                    if ($.common.isEmpty(row.icon)) {
                        return row.title;
                    } else {
                        return '<i class="' + row.icon + '"></i> <span class="nav-label">' + row.title + '</span>';
                    }
                }
            },
            {
                field: 'name',
                title: '编码'
            },
            {
                field: 'order_num',
                title: '排序'
            },
            {
                field: 'visible',
                title: '是否隐藏',
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(visible_datas, value);
                }
            },
            {
                field: 'articles_count',
                title: '文章数量'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                    return actions.join('');
                }
            }]
        };
        $.treeTable.init(options);
    });

</script>
{% endblock %}